
isPyth a b c = a^2 + b^2 == c^2
isSum a b c = a + b + c == 1000
isRight a b c = isSum a b c && isPyth a b c && a < b && b < c

try' :: [Int] -> Int -> (Bool, (Int,Int,Int))
try' [] _ = (False, (-1,-1,-1))
try' bs a
    | isRight a b c = (True,(a,b,c))
    | otherwise = try' (tail bs) a
      where b = head bs
            c = 1000 - a - b

try a = try' [(a+1)..1000] a

answer [] = error "no answer found"
answer (x:xs)
       | fst theTry = snd theTry
       | otherwise = answer xs
         where theTry = try x

main = answer [1..1000]


